<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>DI_USERCONTROL</title>
<meta http-equiv="Content-Type" Content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../../../styles/styles.css">
<script language="javascript" src='../../links.js' type="text/javascript"></script>
</head>
<body>

<h1>DI_USERCONTROL</h1>
<div class=navbar>
<a href="../../index.html">main</a> |
<a href="../index.html">Dialog API</a> |
<a href="index.html">Dialog items</a><br>
</div>

<div class=shortdescr>The <dfn>DI_USERCONTROL</dfn> dialog item describes an user-defined control
controlled completely by the plugin: initialize, draw etc.<br>
</div>

<pre class=syntax>
struct FarDialogItem
{
  int Type          = <b>DI_USERCONTROL</b>
  int X1            = <b>X1</b>
  int Y1            = <b>Y1</b>
  int X2            = <b>X2</b>
  int Y2            = <b>Y2</b>
  int Focus         = <b>User Defined</b>
  CHAR_INFO *VBuf   = <strong>Virtual Draw Buffer</strong>
  DWORD Flags       = <b>Flags</b>
  int DefaultButton = <b>0</b>
  char Data[512]    = <b>User Defined</b>
};
</pre>
<p class=note><img src="../../../images/note.gif" alt="Attention!" width="10" height="10"> Attention!</p>
<UL class=note>
  <LI>This is an exemplary structure; read full description <a href="../structures/fardialogitem.html">here</a>.</LI>
</UL>

<a name="virtbuf"></a>
<h3>Virtual Draw Buffer</h3>
<div class=descr>
<p><dfn>VBuf</dfn> parameter points to an array of <a href="../../winapi/char_info.html">CHAR_INFO</a> structures that contain characters and their attributes to be drawn in the dialog.

<p>If <dfn>VBuf</dfn> is NULL, the plugin itself must draw the control using the
<a href="../../service_functions/text.html">Text</a> service function when a
<a href="../dmsg/dn_drawdlgitem.html">DN_DRAWDLGITEM</a> event comes.
<p>If <dfn>VBuf</dfn> is not NULL, the plugin must fill the <dfn>VBuf</dfn> array when it receives
the <a href="../dmsg/dn_drawdlgitem.html">DN_DRAWDLGITEM</a> event, and the dialog manager will then
copy the contents of the buffer to the screen.

<p>This is the typical scenario for using the <span
class="shortdescr"><dfn>DI_USERCONTROL</dfn></span> (see the source code of
<a href="http://plugring.farmanager.com/downld/files/reversi.rar">Reversi</a> plugin):
<pre class=code>
<font color=#808080>// allocate memory for the virtual buffer before calling DialogEx</font>
<font color=#008000>#define DIM(Item) (((Item).X2-(Item).X1+1)*((Item).Y2-(Item).Y1+1))</font>
CHAR_INFO *VBuf=new CHAR_INFO[DIM(DialogItems[11])];
DialogItems[11].VBuf=VBuf;
  .
  .
  .
<font color=#808080>// in the dialog callback function</font>
struct FarDialogItem DialogItem;

case DN_DRAWDLGITEM:
  if(Param1 == 11)
  {
    char Face[4]="   ";
    SMALL_RECT Rect;
    BYTE AddColor=0x00;

    <font color=#808080>// get coordinates of the dialog and description of the item</font>
    Info.SendDlgMessage(hDlg,DM_GETDLGRECT,0,(LONG_PTR)&amp;Rect);
    Info.SendDlgMessage(hDlg,DM_GETDLGITEM,11,(LONG_PTR)&amp;DialogItem);

    <font color=#808080>// drawing the game field</font>
    for(Y=0; Y &lt; 8; ++Y)
    {
      for(X=0; X &lt; 8; ++X)
      {
        <font color=#808080>// prepare one rectangle</font>

        <font color=#808080>// if the cell is not used...</font>
        if (GAME[0].Field[Y*8+X]==0)
          Face[1]=' ';
        <font color=#808080>// for the white player</font>
        else if (GAME[0].Field[Y*8+X]==GAME[0].Pl1)
        {
          Face[1]=FaceWhite;
          AddColor=0x00;
        }
        <font color=#808080>// for the black player</font>
        else if (GAME[0].Field[Y*8+X]==GAME[0].Pl2)
        {
          Face[1]=FaceBlack;
          AddColor=0x0F;
        }

        <font color=#808080>// if the memory couldn't be allocated</font>,
        <font color=#808080>// draw with the Text function</font>
        if(!DialogItem.VBuf)
        {
          Info.Text(Rect.Left+DialogItem.X1+X*3,
                   Rect.Top+DialogItem.Y1+Y,
                  ColorsPanel[Y&amp;1][X&amp;1]|AddColor,
                  Face);
        }
        else <font color=#808080>// if the memory was allocated, use virtual buffer</font>
        {
          CHAR_INFO *VBuf=&amp;DialogItem.VBuf[Y*8*3+X*3];

          VBuf[0].Char.AsciiChar=Face[0];
          VBuf[1].Char.AsciiChar=Face[1];
          VBuf[2].Char.AsciiChar=Face[2];

          VBuf[0].Attributes=
             VBuf[1].Attributes=
             VBuf[2].Attributes=ColorsPanel[Y&amp;1][X&amp;1]|AddColor;
        }
      }
    }
  }
  return TRUE;
</pre>
</div>

<h3>Flags</h3>
<div class=descr>
There are several flags applicable to the <dfn>DI_USERCONTROL</dfn> control:<br>
<table class="cont">
<tr class="cont"><th class="cont" width="40%">Flag</th><th class="cont" width="60%">Description</th></tr>
 <tr class="cont"><td class="cont" width="40%"><a href="../flags/dif_nofocus.html">DIF_NOFOCUS</a></td>
 <td class="cont" width="60%">The user-defined dialog control cannot receive keyboard focus, but can handle other user events.</td>
 </tr>

 <tr class="cont"><td class="cont" width="40%"><a href="../flags/dif_disable.html">DIF_DISABLE</a></td>
 <td class="cont" width="60%">Disables user access to the control.</td>
 </tr>

 <tr class="cont"><td class="cont" width="40%"><a href="../flags/dif_notcvtusercontrol.html">DIF_NOTCVTUSERCONTROL</a></td>
 <td class="cont" width="60%">do not convert characters (CHAR_INFO::Char) while writing the virtual buffer to the screen.
 </td></tr>

</table>
</div>

<h3>Events</h3>
<div class=descr>
<table class="cont">
<tr class="cont"><th class="cont" width="40%">Event</th><th class="cont" width="60%">Description</th></tr>

 <tr class="cont"><td class="cont" width="40%"><a href="../dmsg/dn_drawdlgitem.html">DN_DRAWDLGITEM</a></td>
 <td class="cont" width="60%">This event is sent to the dialog callback function just before the item is drawn.</td>
 </tr>
 <tr class="cont"><td class="cont" width="40%"><a href="../dmsg/dn_key.html">DN_KEY</a></td>
 <td class="cont" width="60%">This event comes after the user has pressed a key in the dialog.</td>
 </tr>
 <tr class="cont"><td class="cont" width="40%"><a href="../dmsg/dn_mouseclick.html">DN_MOUSECLICK</a></td>
 <td class="cont" width="60%">This event comes after the user has clicked a mouse button; coordinates are counted from upper left corner of the item</td>
 </tr>
 <tr class="cont"><td class="cont" width="40%"><a href="../dmsg/dn_killfocus.html">DN_KILLFOCUS</a></td>
 <td class="cont" width="60%">This event is sent before the button loses focus, if the flag <a href="../flags/dif_nofocus.html">DIF_NOFOCUS</a> was not used.</td>
 </tr>
 <tr class="cont"><td class="cont" width="40%"><a href="../dmsg/dn_killfocus.html">DN_GOTFOCUS</a></td>
 <td class="cont" width="60%">This event is sent after the button has received keyboard focus, if the flag <a href="../flags/dif_nofocus.html">DIF_NOFOCUS</a> was not used.</td>
 </tr>

</table>
</div>

<h3>Remarks</h3>
<div class=descr>
<ol>
<li>For a description of how to manage the text cursor in a user-defined dialog control, see
<a href="../dmsg/dm_getcursorpos.html">DM_GETCURSORPOS</a> or <a href="../dmsg/dm_setcursorpos.html">DM_SETCURSORPOS</a>.
<li>The <span class="shortdescr"><dfn>DI_USERCONTROL</dfn></span> item is not supported by the <a href="../dialog.html">Dialog</a> function.
</ol>
</div>


<div class=see>See also:</div><div class=seecont>
<a href="../structures/fardialogitem.html">FarDialogItem</a>
</div>

</body>
</html>
